home *** CD-ROM | disk | FTP | other *** search
/ The X-Philes (2nd Revision) / The X-Philes Number 1 (1995).iso / xphiles / hp48_1 / trend < prev    next >
Internet Message Format  |  1995-03-31  |  3KB

  1. Path: funic!news.funet.fi!sunic!uupsi!rpi!zaphod.mps.ohio-state.edu!sdd.hp.com!hplabs!hpfcso!rrd
  2. From: rrd@hpfcso.HP.COM (Ray Depew)
  3. Newsgroups: comp.sys.handhelds
  4. Subject: Re: Plotting data point on HP48
  5. Message-ID: <7360065@hpfcso.HP.COM>
  6. Date: 5 Feb 91 17:51:46 GMT
  7. References: <4941@umbc3.UMBC.EDU>
  8. Organization: Hewlett-Packard, Fort Collins, CO, USA
  9. Lines: 65
  10.  
  11. Rouben Rostamian  asks:
  12.  
  13. >How does one plot the graph of a function given in a tabular form?
  14.  
  15. >Specifically, I have a program that generates a sequence of (x,y)
  16. >pairs and stores them in the stack.  The pairs represent points
  17. >on the graph of the solution of a differential equation.
  18. >Does anyone have a utility program for plotting a graph passing
  19. >through these points?  A simple linear interpolation between the points
  20. >will suffice.
  21.  
  22. Here's a quick program that will do what you want.  As with most
  23. connect-the- dots scatter plots, the data points are connected in the 
  24. same order they appear in your array.  This means that your output may
  25. be ugly and disordered, unless you sort your array first.
  26.  
  27. I'm reading this from my 48 display and typing it in here, so pleaswe]
  28. firgove typos.  You may be able to improve on this code, since I put
  29. it together in only a few minutes.
  30.  
  31. Regards
  32. Ray Depew
  33. HP ICBD -- IC's by Bill and Dave   
  34. rrd@hpfitst1.hp.com
  35.  
  36.  
  37. TREND
  38. -----
  39. Draws a SCATTER plot and connects the dots.
  40. Input:  Level 1:  A real array, or the name of a real array.
  41. Output:  Nothing on the stack.  (Draws the plot and displays it.)
  42. Caution:  Use [STAT] {XCOL} and [STAT] {YCOL} to choose your x- and
  43.           y-data columns correctly. 
  44. Checksum: #37143d
  45. Bytes:  253.5
  46.  
  47. Instructions:  Use TREND instead of SCATRPLOT -- that is, use it the same way
  48. you would use SCATRPLOT.  This means that you have to choose XCOL and YCOL 
  49. before you start.  If you want to "pretty up" your plot, you can use LABEL,
  50. AXES, DRAX and the other plotting functions to do so.
  51.  
  52. (In this listing, \GS is Sigma, or "Greek S".  Use [VARS] {\GSDAT}.     
  53.                   \-> is "right arrow".  Use [Rshift][0],
  54.                                           or [PRG]{OBJ}{\->LIST},
  55.                                           or [PRG]{OBJ}[NXT]{R\->C}.
  56.                   \=/ is "not equals".  Use [PRG]{TEST}[NXT]{\=/}.
  57. )
  58.  
  59. \<< SCATRPLOT                @ To set plot limits and draw axes.
  60.   IF DUP TYPE 3 \=/ THEN RCL END    @ Get the array on the stack.
  61.   DUP SIZE 1 GET            @ Array length (number of rows).
  62.   \GSPAR DUP 1 GET            @ x-data column no.
  63.   SWAP 2 GET                @ y-data column no.
  64.   \-> arry n xcol ycol
  65.   \<< 1 n 1 - FOR j            @ Number of line segments to draw.
  66.         arry DUP j xcol 2 \->LIST GET 
  67.         OVER j ycol 2 \->LIST GET R\->C        @ First endpoint.
  68.         OVER j 1 + xcol 2 \->LIST GET
  69.         3 PICK j 1 + ycol 2 \->LIST GET R\->C    @ The other endpoint.
  70.         LINE                @ Draw the line.
  71.       NEXT
  72.       { } PVIEW                @ Keep it in the display for as long
  73.   \>>                    @   as you want it.
  74. \>>
  75.     
  76.